# Compiler settings
CXX = g++
CXXFLAGS = -std=c++14 -Iinclude
LDFLAGS = -llapacke -llapack -lblas

# Phony targets
.PHONY: setup all clean run A CD E F T4 T5 SP plot report doxy

# Default target
all: setup A CD E F T4 T5 SP plot report doxy

# 使用shell的通配符匹配所有.hpp文件
HEADS := $(wildcard include/*.hpp)

# OS Check
ifeq ($(OS),Windows_NT)
    TARGET_EXT = .exe
else
    TARGET_EXT =
endif

# Setup target to create directories
setup:
	mkdir -p images
	mkdir -p output

# Rule for A
A: src/A.cpp
	$(CXX) $(CXXFLAGS) -o A$(TARGET_EXT) src/A.cpp $(LDFLAGS)
	./A$(TARGET_EXT)

# Rule for CD
CD: src/CD.cpp
	$(CXX) $(CXXFLAGS) -o CD$(TARGET_EXT) src/CD.cpp $(LDFLAGS)
	./CD$(TARGET_EXT)

# Rule for E
E: src/E.cpp
	$(CXX) $(CXXFLAGS) -o E$(TARGET_EXT) src/E.cpp $(LDFLAGS)
	./E$(TARGET_EXT)

# Rule for F
F: src/F.cpp
	$(CXX) $(CXXFLAGS) -o F$(TARGET_EXT) src/F.cpp $(LDFLAGS)
	./F$(TARGET_EXT)

# Rule for T4
T4: src/T4.cpp
	$(CXX) $(CXXFLAGS) -o T4$(TARGET_EXT) src/T4.cpp $(LDFLAGS)
	./T4$(TARGET_EXT)

# Rule for T5
T5: src/T5.cpp
	$(CXX) $(CXXFLAGS) -o T5$(TARGET_EXT) src/T5.cpp $(LDFLAGS)
	./T5$(TARGET_EXT)

# Rule for SP
SP: src/SP.cpp
	$(CXX) $(CXXFLAGS) -o SP$(TARGET_EXT) src/SP.cpp $(LDFLAGS)
	./SP$(TARGET_EXT)

# Rule for plot
plot:
	python src/plot.py

# Compile the report and get index.html
report:
	xelatex report.tex
	xelatex report.tex

# Generate doxygen documentation
doxy:
	doxygen Doxyfile

# Run and doc
run: A CD E F T4 T5 SP plot
doc: report doxy

# Clean target
clean:
	rm -f *.o *.exe *.aux *.log *.gz *.pdf *.out *.txt *.toc images/* output/*
	rm -rf Doxydocs 